package pl.enigmatic.random;

import java.util.Collection;
import java.util.List;

import pl.enigmatic.util.Arrays;


public abstract class RandomString extends Random<String> {

	private final DiscreteRandom<Character> chars;

	public RandomString(final List<Character> list) {
		chars = new DiscreteRandom<Character>(list);
	}

	public RandomString() {
		chars = new DiscreteRandom<Character>();
	}

	public RandomString(final Character[] list) {
		chars = new DiscreteRandom<Character>(list);
	}

	public RandomString(final char[] list) {
		this(Arrays.convert(list));
	}

	@Override
	public String getRandomValue() {
		int length = getLength();
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < length; i++) {
			builder.append(chars.get());
		}
		return builder.toString();
	}

	protected abstract int getLength();

	/**
	 * @param arg0
	 * @return
	 * @see pl.enigmatic.random.DiscreteRandom#add(java.lang.Object)
	 */
	public boolean add(Character arg0) {
		return chars.add(arg0);
	}

	/**
	 * @param arg0
	 * @return
	 * @see pl.enigmatic.random.DiscreteRandom#addAll(java.util.Collection)
	 */
	public boolean addAll(Collection<? extends Character> arg0) {
		return chars.addAll(arg0);
	}

}
